//
//  TravelTopicTableView.m
//  ToWhere
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelTopicTableView.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>


@interface TravelTopicTableView ()

@property (nonatomic, retain)UIImageView *imagePic;

@property (nonatomic, retain) UILabel *labelName;

@property (nonatomic, retain) UILabel *labelTitle;

@end

@implementation TravelTopicTableView

-(void)dealloc
{
    [_topicModel release];
    [_labelName release];
    [_labelTitle release];
    [_imagePic release];
    [super dealloc];
    
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createView];
    }
    return self;
}

-(void)createView
{
    self.imagePic = [[UIImageView alloc]init];
    self.imagePic.backgroundColor = [UIColor blueColor];
    
    self.imagePic.layer.masksToBounds = YES;
    self.imagePic.layer.cornerRadius = 5 *kWidth;
    [self addSubview:self.imagePic];
    [_imagePic release];
    
    self.labelName = [[UILabel alloc]init];
    //self.labelName.backgroundColor = [UIColor grayColor];
    
    self.labelName.font = [UIFont systemFontOfSize:20 *kWidth];
    self.labelName.textColor = [UIColor whiteColor];
    [self.imagePic addSubview:self.labelName];
    [_labelName release];
    
    self.labelTitle = [[UILabel alloc]init];
   // self.labelTitle.backgroundColor = [UIColor brownColor];
    self.labelTitle.font = [UIFont systemFontOfSize:15*kWidth];
    self.labelTitle.textColor = [UIColor whiteColor];
    [self.imagePic addSubview:self.labelTitle];
    [_labelTitle release];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imagePic.frame = CGRectMake(5 *kWidth, 5 *kHeight, self.frame.size.width - 10 *kWidth, self.frame.size.height - 5 *kHeight);
    
    self.labelName.frame = CGRectMake(5 *kWidth, self.imagePic.frame.size.height / 3 * 2, self.imagePic.frame.size.width, self.imagePic.frame.size.height / 6);
    self.labelTitle.frame = CGRectMake(5 *kWidth, self.labelName.frame.size.height + self.labelName.frame.origin.y, self.labelName.frame.size.width, self.labelName.frame.size.height);
    
    
}

-(void)setTopicModel:(TravelTopicModel *)topicModel
{
    if (_topicModel != topicModel) {
        [_topicModel release];
        [_topicModel retain];
    }
    
    [self.imagePic sd_setImageWithURL:[NSURL URLWithString:topicModel.image_url] placeholderImage:[UIImage imageNamed:@"Travel_place"]];
    
    self.labelName.text = topicModel.name;
    self.labelTitle.text = topicModel.title;
    
    
    
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
